#include "widget_main.h"
#include "widget_setup_network.h"
#include "widget_setup_local.h"
#include "widget_setup_testing.h"



main_widget::main_widget( QWidget* parent, Qt::WindowFlags flags ): QWidget( parent, flags )
{	
	layout = new QVBoxLayout( this );


	QLabel* title_l = new QLabel( this );
	title_l->setTextFormat( Qt::RichText );
	string title = "<b><font size=8>AI Tester " + string( CLIENT_VERSION ) + "</font></b>";
	title_l->setText( title.c_str() );
	layout->addWidget( title_l );


	layout->addSpacing( 20 );


	single_b = new QPushButton( "Local Game", this );
	connect( single_b, SIGNAL( clicked() ), this, SLOT( single_player() ) );
	layout->addWidget( single_b );


	multi_b = new QPushButton( "Network Game", this );
	connect( multi_b, SIGNAL( clicked() ), this, SLOT( multi_player() ) );
	layout->addWidget( multi_b );


	layout->addSpacing( 10 );


	replay_b = new QPushButton( "Replay", this );
	connect( replay_b, SIGNAL( clicked() ), this, SLOT( replay() ) );
	layout->addWidget( replay_b );


	layout->addSpacing( 10 );


	test_algorithms_b = new QPushButton( "Test Algorithms", this );
	connect( test_algorithms_b, SIGNAL( clicked() ), this, SLOT( test_algorithms() ) );
	layout->addWidget( test_algorithms_b );


	layout->addSpacing( 10 );


	about_qt_b = new QPushButton( "About Qt", this );
	connect( about_qt_b, SIGNAL( clicked() ), this, SLOT( about_qt() ) );
	layout->addWidget( about_qt_b );


	about_b = new QPushButton( "About", this );
	connect( about_b, SIGNAL( clicked() ), this, SLOT( about() ) );
	layout->addWidget( about_b );


	exit_b = new QPushButton( "Exit", this );
	connect( exit_b, SIGNAL( clicked() ), this, SLOT( exit() ) );
	layout->addWidget( exit_b );


	this->setLayout( layout );
	//this->setFixedSize( 198, 317 );
};



void main_widget::single_player()
{
	game_gui* ggui = game_gui::get_instance();
	QScrollArea* sa = new QScrollArea( ggui->g );
	ggui->g->setup_w = new local_setup_widget( sa );
	sa->setWidget( ggui->g->setup_w );
	sa->setWidgetResizable( true );
	ggui->g->main_w->deleteLater();
	ggui->g->main_w = 0;
	ggui->g->setCentralWidget( sa );
	ggui->g->setMinimumSize( 620, 486 );
	ggui->g->resize( 620, 486 );
};



void main_widget::multi_player()
{
	game_gui* ggui = game_gui::get_instance();
	QScrollArea* sa = new QScrollArea( ggui->g );
	ggui->g->setup_w = new network_setup_widget( sa );
	sa->setWidget( ggui->g->setup_w );
	sa->setWidgetResizable( true );
	ggui->g->main_w->deleteLater();
	ggui->g->main_w = 0;
	ggui->g->setCentralWidget( sa );
	ggui->g->setMinimumSize( 665, 339 );
	ggui->g->resize( 665, 339 );
};



void main_widget::replay()
{
	game_gui* ggui = game_gui::get_instance();
	QScrollArea* sa = new QScrollArea( ggui->g );
	ggui->g->replay_w = new replay_widget( sa );
	sa->setWidget( ggui->g->replay_w );
	sa->setWidgetResizable( true );
	ggui->g->main_w->deleteLater();
	ggui->g->main_w = 0;
	ggui->g->setCentralWidget( sa );
	ggui->g->setMinimumSize( 562, 346 );
	ggui->g->resize( 562, 346 );
};



void main_widget::test_algorithms()
{
	game_gui* ggui = game_gui::get_instance();
	QScrollArea* sa = new QScrollArea( ggui->g );
	ggui->g->setup_w = new testing_setup_widget( sa );
	sa->setWidget( ggui->g->setup_w );
	sa->setWidgetResizable( true );
	ggui->g->main_w->deleteLater();
	ggui->g->main_w = 0;
	ggui->g->setCentralWidget( sa );
	ggui->g->setMinimumSize( 751, 441 );
	ggui->g->resize( 751, 441 );
};



void main_widget::about_qt()
{
	qApp->aboutQt();
};



void main_widget::about()
{
	about_widget* aw = new about_widget( this );
	aw->show();
};



void main_widget::exit()
{
	qApp->quit();
};



about_widget::about_widget( QWidget* parent ): QMessageBox( parent )
{
	setWindowTitle( "AI Tester - About" );
	setText( "<h3>About AI Tester</h3>" );
	string text = "<p>AI Tester " + string( CLIENT_VERSION ) + "</p>"
		"<p>This application provides a testing platform for artificial intelligence algorithms for turn based strathegic games."
		   "Besides this main feature, the game implemented can be also played by human players and supports also network games"
		   "using AI Tester Server.</p>"
		"<p>Network game can be played only with AI Tester Server " + string( SERVER_VERSION ) + ".</p>"
		"<p>AI Tester is licensed under the GNU General Public License version 3.0.</p>"
		"<p>Copyright (C) 2010 Tomas Hubik.</p>";
	setInformativeText( text.c_str() );
	setAttribute( Qt::WA_DeleteOnClose );
	QPixmap icon( "AI_Tester.gif" );
    if ( !icon.isNull() )
        setIconPixmap( icon );
};